package kernel.printing;

import graphics.CanvasSlicePlotter;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

/**
 *
 * @author George
 */
public class PrintableTest implements Printable {
    
    private CanvasSlicePlotter canvas;

    public PrintableTest(CanvasSlicePlotter canvas) {
        this.canvas = canvas;
    }
    
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        //trecho de código copiado a partir do link 
        //http://java.sun.com/docs/books/tutorial/2d/printing/examples/PrintUIWindow.java
        //Acesso em: 31/05/2009
        
        if (pageIndex > 0) { /* We have only one page, and 'page' is zero-based */
            return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D)graphics;
        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        g2d.scale(0.5, 0.5);        
        canvas.paint(graphics);
        return PAGE_EXISTS;
    }

}
